<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/10
 * Time: 9:44
 */

namespace app\admin\controller;


use app\admin\model\Admin;
use app\admin\model\YearSurvey;
use app\admin\model\AuthRule;
use app\admin\model\AuthGroup;

class IndexController extends BaseController
{

    public function index()
    {
   //     获取 ADMIN模块 所有的 控制器/方法
//        $pathList = glob( '../application/admin/controller'.'/*.php');
//        foreach ($pathList as $key => $value){
//            $a = get_class_methods('app\admin\controller' . '\\'.substr($value,32,-4));
//            foreach ($a as $k => $v){
//                if($v === 'stopNow'){
//                    break;
//                }
//                $actionsAll[] = ['name' =>substr($value,32,-14) .'/'.$v];
//                $actionsAlls[] = substr($value,32,-14) .'/'.$v;
//            }
//        }
////        //将 所有的 控制器/方法 添加到 规则表内
//        $authRule = new AuthRule;
//        $res = $authRule->find();
//        if($res){
//            foreach ($actionsAll as $v){
//                if($authRule->where(['name' => $v['name']])->find()){
//                    continue;
//                }
//                AuthRule::create(['name' => $v['name']]);
//            }
//        }else{
//            $authRule->saveAll($actionsAll,'false');
//        }
//
//        //将表中的所有数据 取出 删除不存在的
//        $res = $authRule->all();
//        foreach ($res as $v){
//            if(in_array($v['name'],$actionsAlls)){
//                continue;
//            }
//            AuthRule::destroy($v['id']);
//        }
//
//        //写入超级管理员规则
//        $result = $authRule->field('id')->order('id','asc')->select();
//        foreach ($result as $k => $v){
//            $e[] = $v['id'];
//        }
//        $rule = implode(',',$e);
//        $r = AuthGroup::update(['rules' => $rule],['id' => 1]);
//        if($r){
//            echo "<script>console.log('超级管理员规则已写入');</script>";
//        }else{
//            echo "<script>console.log('超级管理员规则写入失败');</script>";
//        }


        $YearSurvey = new YearSurvey();
        $total = $YearSurvey::getTotal();
        $toDay = $YearSurvey->getToDay();
        $yesterDay = $YearSurvey->getYesterDay();
        $toWeek = $YearSurvey->getToWeek();
        $toMon = $YearSurvey->getToMon();
        $last = Admin::where('id',session('admin'))->field('last_login,last_ip')->find();
        $this->assign([
            'total' => $total,
            'toDay' => $toDay,
            'yesterDay' => $yesterDay,
            'toWeek' => $toWeek,
            'toMon' => $toMon,
            'last' => $last,
        ]);
        return $this->fetch();
    }
}